// 引入解密模块
const JSEncrypt = require('node-jsencrypt');



// 加密方法
const encrypt = (ctx, data) => {
    // 使用公钥加密
    const encrypt = new JSEncrypt();
    encrypt.setPublicKey(ctx.state.publicKey)
    const encrypted = encrypt.encrypt(data);
    return encrypted;
}

// 解密方法
const decrypt = (ctx, data) => {
    // 创建decrypt对象，对密码进行解密
    const decrypt = new JSEncrypt();
    decrypt.setPrivateKey(ctx.state.privateKey);
    const decryptData = decrypt.decrypt(data);
    return decryptData;
}

module.exports = {
    encrypt,  // 加密
    decrypt   //解密
}